package app.util;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonUtil {

    public static String appPath(){
        return System.getProperty("user.dir");
    }

    public static String mapVal(Map<String, Object> param, String key){
        if(param == null || param.size() == 0){
            return "";
        }
        if(param.containsKey(key)){
            return param.get(key) == null?"":param.get(key).toString();
        }
        return "";
    }

    /**
     * 匹配字符串中的英文字符
     */
    public static String matchResult(String str) {
        String regEx2 = "[a-z||A-Z]";
        Pattern pattern = Pattern.compile(regEx2);
        StringBuilder sb = new StringBuilder();
        Matcher m = pattern.matcher(str);
        while (m.find()){
            for (int i = 0; i <= m.groupCount(); i++)
            {
                sb.append(m.group());
            }
        }
        return sb.toString();
    }

    /**
     * 下划线命名转为驼峰命名
     */
    public static String underlineToHump(String para){
        StringBuilder result=new StringBuilder();
        String a[]=para.split("_");
        for(String s:a){
            if(result.length()==0){
                result.append(s);
            }else{
                result.append(s.substring(0, 1).toUpperCase());
                result.append(s.substring(1).toLowerCase());
            }
        }
        return result.toString();
    }

    public static String classToHump(String para){
        StringBuilder result=new StringBuilder();
        String a[] = para.split("_");
        for(String s:a){
            result.append(s.substring(0, 1).toUpperCase());
            result.append(s.substring(1).toLowerCase());
        }
        return result.toString();
    }

}
